package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

//    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("获取到的文件:{}", file);
        if (!file.isEmpty()) {
            //调用工具类方法生成一个图片的url
            String url = aliyunOSSOperator.upload(file.getBytes(), file);
            log.info("生成的图片url:{}", url);
            return Result.success(url);
        }
        return Result.error("上传失败");
    }

}
